<template>
    <div class="all">
      <div class="top">
        <header>
          <div class="div">
            <img src="../../../assets/返回.png" @click="back()" alt="">
            <span class="solid" @click="back()">上一步</span>
          </div>
          <div class="div">
            <span>{{ typeTitle }}</span>
          </div>
          <div class="div">
            <span class="solid" @click="next()">下一步</span>
          </div>
        </header>
        <div class="menu">
          <el-steps :active="menuIndex" align-center>
            <el-step title=""
                     v-for="(item, index) in ( type== 5 ? menuList5 : menuList)"
                     :key="index"
                     @click.native="changeMenu(index, url)"
                     process-status="success"
                     :description="item.title">
<!--            (type == 1 ? menuList1 : type == 2 ? menuList2 : type== 5 ? menuList5 : menuList1)"-->
              <template #icon>
                <div v-if="menuIndex >= index" style="width: 15px;height: 15px;">
                  <img src="../../../assets/步骤选择.png" style="width: 15px;height: 15px;" alt="">
                </div>
                <div v-else style="width: 6px;height: 15px;background: #1DA4F2;display: flex;align-items: center;justify-content: center">
                  <a style="width: 6px;height: 6px;border-radius: 50%;background: white;display: flex;position: absolute;"></a>
                </div>
              </template>
            </el-step>
          </el-steps>
        </div>
      </div>
<!--      <div class="peopleList">
        <div class="title" style="position: sticky;top: 0"><span class="title_left"><a class="hengGang"></a>选择接受{{typeLabel}}人 （{{peopleList.length}}人）</span></div>
        <div class="peopleDiv" @click.stop="selectPeople(item)" v-for="(item, index) in peopleList" :key="index">
          <div class="peopleLeft">
            <img class="photo" v-if="item.SEX == 1" src="../../../assets/男-被服务@2x.png" alt="">
            <img class="photo" v-else-if="item.SEX == 2" src="../../../assets/女-被服务@2x.png" alt="">
          </div>
          <div class="peopleContent">
            <p>
              <span class="name">{{item.name}}</span>
              <span class="age">{{item.age}}岁</span>
              &lt;!&ndash;              0本人 1配偶 2父母 3子女 4其他&ndash;&gt;
              <button v-show="item.TIPS == 0" class="biaoqian">本人</button>
              <button v-show="item.TIPS == 1" class="biaoqian biaoqianBlue">配偶</button>
              <button v-show="item.TIPS == 2" class="biaoqian biaoqianBlue">父母</button>
              <button v-show="item.TIPS == 3" class="biaoqian biaoqianBlue">子女</button>
              <button v-show="item.TIPS == 4" class="biaoqian biaoqianBlue">其他</button>
            </p>
            <p class="phone">手机号: {{item.phone}}</p>
          </div>
          <div class="peopleRight">
            <img v-if="PATIENT_USER_ID !== item.PATIENT_USER_ID" src="../../../assets/蓝未选择.png" alt="">
            <img v-else src="../../../assets/题目选择.png" alt="">
          </div>
        </div>
      </div>-->
<!--      <div class="peopleList"  v-show="type !== 1" style="box-shadow: 0px -5px 10px 0px rgba(0, 0, 0, 0.1);">
        <div class="title" style="position: sticky;top: 0">
          <span class="title_left"><a class="hengGang"></a>
          选择参与人 （{{type === 5 ? peopleList.length-1 : peopleList.length}}人）
          </span>
        </div>
        <div class="peopleDiv"
             @click.stop="chooseAccompany(item, index)"
             v-for="(item, index) in peopleList" :key="index"
             v-show="type === 5 ? PATIENT_USER_ID !== item.PATIENT_USER_ID : true">
          <div class="peopleLeft">
            <img class="photo" v-if="item.SEX == 1" src="../../../assets/男-被服务@2x.png" alt="">
            <img class="photo" v-else-if="item.SEX == 2" src="../../../assets/女-被服务@2x.png" alt="">
          </div>
          <div class="peopleContent">
            <p>
              <span class="name">{{item.name}}</span>
              <span class="age">{{item.age}}岁</span>
              &lt;!&ndash;              0本人 1配偶 2父母 3子女 4其他&ndash;&gt;
              <button v-show="item.TIPS == 0" class="biaoqian">本人</button>
              <button v-show="item.TIPS == 1" class="biaoqian biaoqianBlue">配偶</button>
              <button v-show="item.TIPS == 2" class="biaoqian biaoqianBlue">父母</button>
              <button v-show="item.TIPS == 3" class="biaoqian biaoqianBlue">子女</button>
              <button v-show="item.TIPS == 4" class="biaoqian biaoqianBlue">其他</button>
            </p>
            <p class="phone">手机号: {{item.phone}}</p>
          </div>
          <div class="peopleRight">
            <img v-if="item.chooseCanyu === true" src="../../../assets/题目选择.png" alt="">
            <img v-else src="../../../assets/蓝未选择.png" alt="">
          </div>
        </div>
      </div>-->
      <van-collapse v-model="activeNames">
        <van-collapse-item  name="1">
          <template #title>
            <div class="label">
              <span class="title_left">
              <a class="hengGang"></a>选择接受{{typeLabel}}人 （{{peopleList.length}}人）
              </span>
            </div>
          </template>
          <div class="peopleDiv" @click.stop="selectPeople(item)" v-for="(item, index) in peopleList" :key="index">
            <div class="peopleLeft">
              <img class="photo" v-if="item.SEX == 1" src="../../../assets/男-被服务@2x.png" alt="">
              <img class="photo" v-else-if="item.SEX == 2" src="../../../assets/女-被服务@2x.png" alt="">
            </div>
            <div class="peopleContent">
              <p>
                <span class="name">{{item.name}}</span>
                <span class="age">{{item.age}}岁</span>
                <!--              0本人 1配偶 2父母 3子女 4其他-->
                <button v-show="item.TIPS == 0" class="biaoqian">本人</button>
                <button v-show="item.TIPS == 1" class="biaoqian biaoqianBlue">配偶</button>
                <button v-show="item.TIPS == 2" class="biaoqian biaoqianBlue">父母</button>
                <button v-show="item.TIPS == 3" class="biaoqian biaoqianBlue">子女</button>
                <button v-show="item.TIPS == 4" class="biaoqian biaoqianBlue">其他</button>
              </p>
              <p class="phone">手机号: {{item.phone}}</p>
            </div>
            <div class="peopleRight">
              <img v-if="PATIENT_USER_ID !== item.PATIENT_USER_ID" src="../../../assets/蓝未选择.png" alt="">
              <img v-else src="../../../assets/题目选择.png" alt="">
            </div>
          </div>
        </van-collapse-item>
        <van-collapse-item  name="2">
          <template #title>
            <div class="label">
              <span class="title_left">
              <a class="hengGang"></a>选择参与人 （{{type === 5 ? peopleList.length-1 : peopleList.length}}人）
              </span>
            </div>
          </template>
          <div class="peopleDiv"
               @click.stop="chooseAccompany(item, index)"
               v-for="(item, index) in peopleList" :key="index"
               v-show="type === 5 ? PATIENT_USER_ID !== item.PATIENT_USER_ID : true">
            <div class="peopleLeft">
              <img class="photo" v-if="item.SEX == 1" src="../../../assets/男-被服务@2x.png" alt="">
              <img class="photo" v-else-if="item.SEX == 2" src="../../../assets/女-被服务@2x.png" alt="">
            </div>
            <div class="peopleContent">
              <p>
                <span class="name">{{item.name}}</span>
                <span class="age">{{item.age}}岁</span>
                <!--              0本人 1配偶 2父母 3子女 4其他-->
                <button v-show="item.TIPS == 0" class="biaoqian">本人</button>
                <button v-show="item.TIPS == 1" class="biaoqian biaoqianBlue">配偶</button>
                <button v-show="item.TIPS == 2" class="biaoqian biaoqianBlue">父母</button>
                <button v-show="item.TIPS == 3" class="biaoqian biaoqianBlue">子女</button>
                <button v-show="item.TIPS == 4" class="biaoqian biaoqianBlue">其他</button>
              </p>
              <p class="phone">手机号: {{item.phone}}</p>
            </div>
            <div class="peopleRight">
              <img v-if="item.chooseCanyu === true" src="../../../assets/题目选择.png" alt="">
              <img v-else src="../../../assets/蓝未选择.png" alt="">
            </div>
          </div>
        </van-collapse-item>

      </van-collapse>

      <div class="title" style="
box-shadow: 0px -5px 10px 0px rgba(0, 0, 0, 0.1);">
        <span class="title_left">
          <a class="hengGang"></a>
          {{typeLabel}}人情况
        </span>
        <span @click="show = true" class="title_right">
          如何描述？
        </span>
      </div>
      <div class="text">
        <textarea v-model="illness_desc" :placeholder="`请输入您要` +typeLabel+`的情况`" style="resize: none" name="" id="" cols="30" rows="10"></textarea>
      </div>
      <ul class="ulList">
        <li  >
          <span class="li_label">是否需要医生指导用药</span>
          <span class="li_input">
            <a @click.stop="clickIs_doc_medical(0)">不需要
              <img class="selectImg"  v-if="is_doc_medical == 0" src="../../../assets/题目选择.png" alt="">
              <img class="selectImg" v-else  src="../../../assets/蓝未选择.png" alt="">
            </a>
             <a @click.stop="clickIs_doc_medical(1)">需要
                <img class="selectImg"  v-if="is_doc_medical == 1" src="../../../assets/题目选择.png" alt="">
              <img class="selectImg" v-else src="../../../assets/蓝未选择.png" alt="">
            </a>
          </span>
        </li>
        <li v-cloak v-show="isYoung === true">
          <span class="li_label">体重</span>
          <span class="li_input">
            <input type="text" v-model="weight" style="margin-right: 5px" placeholder="请输入体重">
            kg
          </span>
        </li>
        <li >
          <span class="li_label">是否曾到医疗机构就诊</span>
          <span class="li_input">
            <a @click.stop="clickIs_hos_visit(0)">未到过
              <img class="selectImg" v-if="is_hos_visit == 0" src="../../../assets/题目选择.png" alt="">
              <img class="selectImg" v-else   src="../../../assets/蓝未选择.png" alt="">
            </a>
             <a @click.stop="clickIs_hos_visit(1)">到过
              <img class="selectImg"  v-if="is_hos_visit == 1" src="../../../assets/题目选择.png" alt="">
              <img class="selectImg" v-else src="../../../assets/蓝未选择.png" alt="">
            </a>
          </span>
        </li>
      </ul>
      <div class="title" @click="shouQuan" style="margin-top: 5px;align-items: center">
        <span style="display: flex;
  align-items: center;
  font-size: 15px;font-weight: bold">
            <a class="hengGang"></a>健康档案调阅
        </span>
        <span style="font-size: 15px">
          {{OLIST_update == true ? '修改授权' : '建议授权'}}
          <img style="width: 7px;height: 13px;" src="../../../assets/更多灰.png" alt="">
        </span>
      </div>
      <div style="background: #fff;font-size: 13px;
font-family: PingFang SC;
font-weight: 500;
color: #999999;
padding: 0 15px;box-sizing: border-box;line-height: 1.8;text-indent: 1em">
        {{OLIST_update == true ?
        '您的健康档案调阅功能已经开启。您授权调阅的档案信息仅您和提供咨询人可见。'
        :
        '为方便就诊，您的健康档案调阅功能需要授权开启。为保证您的隐私安全，您授权调阅的档案信息仅您和提供咨询人可见。'
        }}
      </div>
      <div class="box" style="margin-top: 5px;">
        <div class="title" >
        <span style="display: flex;align-items: center;
  font-size: 15px;font-weight: bold">
            <a class="hengGang"></a>上传{{typeTitle}}相关的资料图片(最多上传9张图片)
        </span>
        </div>
        <div class="imgDiv">
          <van-uploader v-model="fileList"
                        max-count="9"
                        :upload-icon="require('../../../assets/上传图片.png')"
                        multiple="true"
                        @delete="Delete"
                        :before-delete="beforeDel"
                        image-fit="cover"
                        accept="image/*"
                        preview-size="28vw"
                        :after-read="updateFile"
          />
        </div>
        <div class="tishi" style="text-indent: 1em">
          为确保您的隐私安全，上传的图片资料仅您和提供咨询人可见。
        </div>
      </div>

<!--      <button class="imgUpload" @click="upload()">-->
<!--        <img src="../../../assets/新建.png" alt="">-->
<!--        上传{{typeTitle}}相关资料-->
<!--      </button>-->
      <van-overlay :show="show" @click="show = false">
        <div class="wrapper" @click.stop>
          <div class="block" >
            <div class="popTop">如何描述</div>
            <div class="popContent">
              <p>
                请描述疾病名称或者症状，患病时间，做过什么检查，用药情况，目前是加重还是缓解，想要获得医生什么帮助？描述越详细，医生回复质量越高。
              </p>
              <p>
                【例】女儿三岁，上周一感冒咳嗽流鼻涕，医院检查说是支原体感染（报告单详见照片），阿奇颗粒吃了三天有好转，但隔了两天又开始咳嗽流鼻涕，请问医生接下来应该如何治疗？
              </p>
            </div>
            <div class="popBottom" @click="show = false">
              知道了
            </div>
          </div>
        </div>
      </van-overlay>

      <van-popup v-model="isdoctorShow" round position="bottom" >
        <van-picker
          :default-index="isdoctorIndex"
          title="是否需要医生指导用药"
          show-toolbar
          :columns="isdoctorColumns"
          @confirm="isdoctoronConfirm"
          @cancel="isdoctorShow = false"
        />
      </van-popup>
      <van-popup v-model="isHosShow" round position="bottom" >
        <van-picker
          :default-index="isHosIndex"
          title="是否曾到医疗机构就诊"
          show-toolbar
          :columns="isHosColumns"
          @confirm="isHosonConfirm"
          @cancel="isHosShow = false"
        />
      </van-popup>
      <van-dialog v-model="writeShow"
                  width="80%"
                  confirm-button-color="#1da4f2"
                  title="即将进入支付页面，请确认您已填写的信息是否正确？"
                  @confirm="writeConfirm()"
                  show-cancel-button>
      </van-dialog>
      <div v-show="isLoading"
        style="width: 100%;height: 100%;display: flex;align-items: center;justify-content: center;position: absolute;top: 0;background: rgba(0, 0, 0, 0.5)" >
        <van-loading size="24px" type="spinner" color="#fff">订单生成中...</van-loading>
      </div>
    </div>
</template>

<script>
import {Toast} from 'vant'
import lrz from 'lrz'
export default {
  name: 'TuWenSecondAdd',
  data () {
    return {
      menuIndex: 2,
      menuList: [
        {
          title: '选择医生/团队',
          url: '/first'
        },
        {
          title: '预约信息',
          url: '/tuWenPrice'
        },
        {
          title: '咨询准备',
          url: '/second'
        },
        {
          title: '费用支付',
          url: '/third'
        }
      ],
      menuList5: [
        {
          title: '选择医生/团队',
          url: '/first'
        },
        {
          title: '预约信息',
          url: '/tuWenPrice'
        },
        {
          title: '会诊准备',
          url: '/second'
        },
        {
          title: '费用支付',
          url: '/third'
        }
      ],
      show: false,
      isdoctorColumns: [
        {'keyId': 1, 'text': '是'},
        {'keyId': 0, 'text': '否'}
      ],
      isdoctorShow: false,
      isHosShow: false,
      isdoctorIndex: '',
      isHosIndex: '',
      isdoctorVal: '',
      isHosVal: '',
      isHosColumns: [
        {'keyId': 1, 'text': '是'},
        {'keyId': 0, 'text': '否'}
      ],
      peopleList: [],
      name: '',
      isYoung: false,
      weight: '', // 体重
      illness_desc: '', // 病情描述
      is_doc_medical: 0, // 是否需要医生指导用药 0:否;1:是
      is_hos_visit: 0, // 是否曾到医疗机构就诊 0:否;1:是
      type: Number(this.$route.query.type),
      PATIENT_USER_ID: '', // 被服务人userid
      writeShow: false,
      isLoading: false,
      fileList: [],
      isSend: true,
      imgList: [],
      Plist: [],
      activeNames: ['1'],
      OLIST_update: false // 判断是否选择过健康档案授权
    }
  },
  mounted () {
    this.getPeople()
    if (sessionStorage.getItem('peopleInfo') !== null) {
    }
    if (sessionStorage.getItem('SecondData')) {
      var data = JSON.parse(sessionStorage.getItem('SecondData'))
      this.name = data.name

      this.weight = data.weight // 体重
      this.illness_desc = data.illness_desc // 病情描述
      this.is_doc_medical = data.is_doc_medical // 是否需要医生指导用药 0:否;1:是
      this.is_hos_visit = data.is_hos_visit // 是否曾到医疗机构就诊 0:否;1:是
      this.isdoctorIndex = data.isdoctorIndex
      this.isHosIndex = data.isHosIndex
      this.isdoctorVal = data.isdoctorVal
      this.isHosVal = data.isHosVal
      this.PATIENT_USER_ID = data.PATIENT_USER_ID
      this.Plist = data.Plist
      if (data.Olist && data.Olist.length > 0) {
        this.OLIST_update = true
      }
      if (data.imgList === undefined || data.imgList === '' || data.imgList === null) {
        this.imgList = []
        this.fileList = []
      } else {
        this.imgList = data.imgList
        this.fileList = data.fileList
      }
    }
    if (sessionStorage.getItem('DATA')) {
      let data = JSON.parse(sessionStorage.getItem('DATA'))
      if (data.Olist && data.Empowerlist) {
      } else {
        this.getOlist()
      }
    }
  },
  computed: {
    OLIST: function () {
      let data = JSON.parse(sessionStorage.getItem('DATA'))
      if (data.Olist) {
      } else {
        // this.getOlist()
        // // data.Olist = []
      }
      return data.Olist.length
    },
    typeTitle: function () {
      if (this.type === 1) {
        document.title = '图文咨询'
        return '图文咨询'
      } else if (this.type === 2) {
        document.title = '视频咨询'
        return '视频咨询'
      } else if (this.type === 5) {
        document.title = '远程会诊'
        return '远程会诊'
      }
    },
    typeLabel: function () {
      if (this.type !== 5) {
        return '咨询'
      } else {
        return '会诊'
      }
    }
  },
  watch: {
  },
  methods: {
    getOlist () {
      this.$http.listHealthOauth({})
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            let list = []
            for (let i in res.data.data) {
              for (let k in res.data.data[i].oauths) {
                let obj
                obj = {
                  'oauth_type': 0,
                  'oauth_id': res.data.data[i].oauths[k].id
                }
                list.push(obj)
              }
            }
            let data = JSON.parse(sessionStorage.getItem('DATA'))
            data.Olist = list
            sessionStorage.setItem('DATA', JSON.stringify(data))
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    shouQuan () {
      this.$router.push({path: '/EmpowerList', query: {type: this.type}})
    },
    // 选择参与人
    chooseAccompany (item, index) {
      if (this.type === 1 || this.type === 2) {
        if (item.chooseCanyu === true) {
          item.chooseCanyu = !item.chooseCanyu
        } else {
          this.peopleList.map((odd, index) => {
            this.$set(odd, 'chooseCanyu', false)
          })
          item.chooseCanyu = !item.chooseCanyu
        }
      } else if (this.type === 5) {
        if (item.chooseCanyu !== undefined) {
          item.chooseCanyu = !item.chooseCanyu
        } else {
          this.$set(item, 'chooseCanyu', true)
        }
      }

      if (this.type === 1 || this.type === 2) {
        this.Plist = []
      }

      if (item.chooseCanyu === true) {
        this.$set(this.Plist, index, item.PATIENT_USER_ID)
      } else {
        this.Plist.splice(index, 1)
      }
      console.log(this.peopleList)
    },
    // 删除图片
    Delete (file, detail) {
      this.imgList.splice(detail.index, 1)
    },
    // 删除之前
    beforeDel (detail) {
      if (this.isSend === true) {
        return true
      } else {
        Toast('请上传完之后再进行操作')
        return false
      }
    },
    // 上传
    updateFile (file) {
      this.fileUpload(file, 0)
    },
    // 上传图片请求操作
    fileUpload (file, i) {
      if (file.length === undefined) {
        this.isSend = false
        file.status = 'uploading'
        file.message = '正在上传中...'
        if (file.file !== undefined) {
          lrz(file.file, {
            width: 2000,
            quality: 0.7 // 图片压缩质量，取值0-1，默认为0.7
          })
            .then((rst) => {
              this.$http.img({base64: rst.base64, type: 4})
                .then(res => {
                  console.log(res)
                  if (res.data.status === 'success') {
                    this.imgList.push(res.data.data)
                    this.isSend = true
                    file.status = ''
                    file.message = ''
                  }
                })
                .catch(err => {
                  console.log(err)
                })
            })
            .catch((error) => {
              console.log('失败', error)
              // this.fileUpload(file[i].content, file, i)
              // 失败时执行
            })
        } else {
          lrz(file, {
            width: 2000,
            quality: 0.7 // 图片压缩质量，取值0-1，默认为0.7
          })
            .then((rst) => {
              this.$http.img({base64: rst.base64, type: 4})
                .then(res => {
                  console.log(res)
                  if (res.data.status === 'success') {
                    this.imgList.push(res.data.data)
                    this.isSend = true
                    file.status = ''
                    file.message = ''
                  }
                })
                .catch(err => {
                  console.log(err)
                })
            })
            .catch((error) => {
              console.log('失败', error)
              // this.fileUpload(file[i].content, file, i)
              // 失败时执行
            })
        }
      } else {
        if (i === file.length) { //  || this.fileList.length > 8
          this.isSend = true
          return false
        }
        this.isSend = false
        if (i === 0) {
          for (var j = 0; j < file.length; j++) {
            file[j].status = 'uploading'
            file[j].message = '正在上传中...'
          }
        }
        lrz(file[i].file, {
          width: 2000,
          quality: 0.7 // 图片压缩质量，取值0-1，默认为0.7
        })
          .then((rst) => {
            this.$http.img({base64: rst.base64, type: 4})
              .then(res => {
                console.log(res)
                if (res.data.status === 'success') {
                  this.imgList.push(res.data.data)
                  file[i].status = ''
                  file[i].message = ''
                  i++
                  this.fileUpload(file, i)
                }
              })
              .catch(err => {
                console.log(err)
              })
          })
          .catch((error) => {
            console.log('失败', error)
          })
      }
    },
    // 选择被服务人
    selectPeople (item) {
      this.Plist = []
      this.name = item.name
      if (item.age < 6) {
        this.isYoung = true
        this.weight = ''
      } else {
        this.isYoung = false
        this.weight = ''
      }
      this.PATIENT_USER_ID = item.PATIENT_USER_ID
    },
    clickIs_hos_visit (id) {
      this.is_hos_visit = id
    },
    // 是否需要医生指导
    clickIs_doc_medical (id) {
      this.is_doc_medical = id
    },
    // // 点击上传相关资料
    // upload () {
    //   if (this.PATIENT_USER_ID === '' || this.PATIENT_USER_ID === null || this.PATIENT_USER_ID === undefined) {
    //     Toast('请选择被服务人')
    //     return false
    //   }
    //   this.$router.push({path: '/tuWenUpload', query: {'type': this.type}})
    // },
    // 返回
    back () {
    // this.$router.push({path: '/tuWenHome', query: {'type': this.type}})
      this.$router.history.go(-1)
    },
    // 提交生成订单
    writeConfirm () {
      this.writeShow = false
      this.isLoading = true

      var data = JSON.parse(sessionStorage.getItem('DATA'))
      data.illness_desc = this.illness_desc // 病情描述
      data.is_doc_medical = this.is_doc_medical // 是否需要医生指导用药
      data.is_hos_visit = this.is_hos_visit // 是否曾到医疗机构就诊
      data.weight = this.weight // 体重
      data.patient_user_id = this.PATIENT_USER_ID
      if (data.Olist) {
      } else {
        data.Olist = []
      }
      if (sessionStorage.getItem('order') !== null) {
        this.$router.push({path: '/third', query: {'type': this.type}})
      } else {
        let obj = {
          'type': data.type.toString(), // '咨询类型 1:图文咨询;2:视频咨询',
          'doc_user_id': data.doc_user_id, // '医生ID',
          'illness_desc': this.illness_desc, // 病情描述
          'doc_advise': data.doc_advise,
          'doc_amount_type': data.doc_amount_type, // 订单价格类型
          'amount': data.amount, // 咨询订单价格
          'is_doc_medical': this.is_doc_medical, // 是否需要医生指导用药 0:否;1:是
          'is_hos_visit': this.is_hos_visit, // 是否曾到医疗机构就诊 0:否;1:是
          'Iimg': data.Iimg, // 图片集合 // data.Iimg
          'Clist': data.Clist, // data.Clist
          'Jlist': data.Jlist, // data.Jlist
          'patient_user_id': this.PATIENT_USER_ID, // 被服务id
          'doc_amount_name': data.doc_amount_name, // 项目名称
          Olist: data.Olist // 权限
        }
        if (this.weight !== '' && this.weight !== null && this.weight !== undefined) {
          obj.weight = this.weight
        }
        if (data.team_id) {
          obj.team_id = data.team_id
          obj.team_doc_id = data.team_doc_id
        }
        // 视频 和 远程
        if (this.type === 2 || this.type === 5) {
          obj.doc_amount_duration = data.doc_amount_duration // 时长
          obj.schedule_id = data.schedule_id // 排班id
          obj.book_date = data.book_date
          obj.book_time_start = data.book_time_start
          obj.book_time_end = data.book_time_end
        }
        // 陪诊人
        let chooseList = []
        for (let i in this.Plist) {
          if (this.Plist[i] !== null) {
            var okk = {
              partake_user_id: this.Plist[i]
            }
            chooseList.push(okk)
          } else {
          }
        }
        obj.Plist = chooseList
        console.log(obj)
        this.$http.saveInquary(obj)
          .then(res => {
            console.log(res)
            if (res.data.status === 'success') {
              this.isLoading = false
              sessionStorage.setItem('order', JSON.stringify(res.data.data))
              this.$router.push({path: '/third', query: {'type': this.type}})

              // 清空指定对象的聊天信息  clearChatMessage
              // 参数：指定对象的userid（医生id）   生成订单执行
              if (sessionStorage.getItem('sys') === 'ANDROID') {
                window.WebViewJavascriptBridge.callHandler('clearChatMessage', data.doc_user_id, function (responseData) {
                })
              }
            } else {
              Toast(res.data.msg)
            }
          })
          .catch(err => {
            console.log(err)
            Toast('请求错误')
          })

        sessionStorage.setItem('DATA', JSON.stringify(data))
      }
    },
    // 下一步
    next () {
      if (this.PATIENT_USER_ID === '' || this.PATIENT_USER_ID === null || this.PATIENT_USER_ID === undefined) {
        Toast('请选择被服务人')
        return false
      }
      if (this.illness_desc === '') {
        Toast('请输入' + this.typeLabel + '描述')
        return false
      }
      if (this.is_doc_medical === '') {
        Toast('请选择是否需要医生指导用药')
        return false
      }
      if (this.isYoung === true && this.weight === '') {
        Toast('请输入体重')
        return false
      }
      if (this.is_hos_visit === '') {
        Toast('请选择是否曾到医疗机构就诊')
        return false
      }
      if (this.isSend === false) {
        Toast('图片上传中，请稍后')
        return false
      }
      var data = JSON.parse(sessionStorage.getItem('DATA'))
      data.Iimg = []
      data.fileList = []
      console.log(this.imgList)
      for (var i = 0; i < this.imgList.length; i++) {
        let obj = {
          picture: this.imgList[i]
        }
        let file = { url: this.imgList[i], isImage: true }
        data.fileList.push(file)
        data.Iimg.push(obj)
      }
      sessionStorage.setItem('DATA', JSON.stringify(data))
      this.writeShow = true
    },
    changeMenu (index) {
    },
    // 获取被服务人信息
    getPeople () {
      this.$http.findPatient()
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            this.peopleList = res.data.data
            let data = sessionStorage.getItem('DATA')
            if (data.patient_user_id === '' || data.patient_user_id === undefined || data.patient_user_id === null) {
              this.PATIENT_USER_ID = this.peopleList[0].PATIENT_USER_ID
              this.name = this.peopleList[0].name
              if (this.peopleList[0].age < 6) {
                this.isYoung = true
                this.weight = ''
              } else {
                this.isYoung = false
                this.weight = ''
              }
              if (this.Plist.length <= 0 && this.type !== 5) {
                // this.$set(this.peopleList[0], 'chooseCanyu', true)
                this.chooseAccompany(this.peopleList[0], 0)
              } else {
                this.peopleList.map((item, index) => {
                  this.Plist.map((okk, okkIndex) => {
                    if (item.PATIENT_USER_ID === okk) {
                      this.$set(item, 'chooseCanyu', true)
                    }
                  })
                })
              }
              console.log(this.peopleList)
            }
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    // 是否需要医生指导
    isdoctoronConfirm (value, index) {
      console.log(value.text)
      this.is_doc_medical = value.keyId
      this.isdoctorShow = false
      this.isdoctorVal = value.text
      this.isdoctorIndex = index
    },
    // 是否曾到医疗机构就诊
    isHosonConfirm (value, index) {
      console.log(value)
      this.is_hos_visit = value.keyId
      this.isHosShow = false
      this.isHosVal = value.text
      this.isHosIndex = index
    }
  },
  destroyed () {
    this.fileList = []
    for (var i = 0; i < this.imgList.length; i++) {
      let file = { url: this.imgList[i], isImage: true }
      this.fileList.push(file)
    }
    // console.log(this.Plist)
    // let chooseList = []
    // for (let i in this.Plist) {
    //   var okk = {
    //     partake_user_id: this.Plist[i]
    //   }
    //   chooseList.push(okk)
    // }
    var obj = {
      name: this.name,
      weight: this.weight, // 体重
      illness_desc: this.illness_desc, // 病情描述
      is_doc_medical: this.is_doc_medical, // 是否需要医生指导用药 0:否;1:是
      is_hos_visit: this.is_hos_visit, // 是否曾到医疗机构就诊 0:否;1:是
      isdoctorIndex: this.isdoctorIndex,
      isHosIndex: this.isHosIndex,
      isdoctorVal: this.isdoctorVal,
      isHosVal: this.isHosVal,
      PATIENT_USER_ID: this.PATIENT_USER_ID,
      isYoung: this.isYoung,
      fileList: this.fileList,
      imgList: this.imgList,
      Plist: this.Plist
    }
    sessionStorage.setItem('SecondData', JSON.stringify(obj))
  }
}
</script>

<style scoped >
  .all{
    width: 100%;
    height: 100%;
    overflow: auto;
    background: #FAF9FE;
  }
  .top{
    position: sticky;
    top: 0;
    background: white;
    z-index: 99;
  }
  header{
    width: 100%;
    height: 44px;
    display: flex;
    align-items: center;
    font-family: "PingFang SC";
  }
  .menu{
    width: 100%;
    height: 60px;
    background: #1DA4F2;
    box-shadow: 0px 1px 0px 0px #E5E5E5;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow:hidden;
  }
  .div{
    width: 33%;
    font-size: 15px;
    font-weight: bold;
    display: flex;
    align-items: center;
  }
  .div:nth-child(1) img{
    width: 7px;
    height: 13px;
    margin: 0 5px 0 15px;
  }
  .div:nth-child(2){
    justify-content: center;
  }
  .div:nth-child(3){
    justify-content: flex-end;
  }
  .div:nth-child(3) span{
    margin-right: 15px;
  }
  .solid{
    color: #1DA4F2;
  }
  .hengGang{
    display: block;
    width: 2px;
    border-radius: 1px;
    height: 15px;
    background: #1DA4F2;
    margin-right: 5px;
  }
  .title{
    width: 100%;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    box-sizing: border-box;
    background: white;
  }
  .label{
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .title_left{
    height: 100%;
    display: flex;
    align-items: center;
    font-size: 15px;
    font-family: PingFang SC;
    font-weight: bold;
    color: #333333;
  }
  .title_right{
    font-size: 13px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #1DA4F2;
  }
  .text{
    width: 100%;
    /*height: 150px;*/
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .text textarea{
    width: 92%;
    height: 130px;
    margin: 0 auto;
    border-radius: 10px;
    background: #FAF9FE;
    /*border: none;*/
    border-color: #999;
    padding: 10px;
    box-sizing: border-box;
    font-size: 13px;
    font-family: PingFang SC;
    font-weight: 500;
  }
  .ulList{
    width: 100%;
    background: white;
    padding:  0 15px;
    box-sizing: border-box;
    margin-bottom: 5px;
    /*margin-bottom: 60px;*/
  }
  .ulList li{
    width: 100%;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #E5E5E5;
  }
  .li_label{
    font-size: 15px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #333333;
  }
  /*.li_input img{*/
  /*  width: 13px;*/
  /*  height: 7px;*/
  /*}*/
  .selectImg{
    width: 15px;
    height: 15px;
    margin-left: 5px;
    margin-right: 8px;
  }
  .li_input{
    display: flex;
    align-items: center;
    font-size: 15px;
  }
  .li_input input{
    width: 110px;
    text-align: right;
    border: none;
    font-size: 15px;
  }
  .li_input a{
    display: flex;
    align-items: center;
  }
  .wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
  }

  .block {
    width: 90%;
    height: 40%;
    background-color: #fff;
    border-radius: 10px;
    position: absolute;
    overflow: hidden;
  }
  .popTop{
    width: 100%;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    font-weight: bold;
    font-family: "PingFang SC";
    position: sticky;
    top: 0;
    background: white;
  }
  .popAllpeople{
    height: 76%;
  }
  .popContent{
    height: 70%;
    font-size: 13px;
    font-weight: 500;
    font-family: "PingFang SC";
    overflow: auto;
    padding: 0 10px;
    box-sizing: border-box;
  }
  .popContent p:nth-child(1){
    margin-bottom: 10px;
  }
  .popBottom{
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 44px;
    position: absolute;
    bottom: 0;
    font-size: 17px;
    font-weight: bold;
    font-family: "PingFang SC";
    color: #1DA4F2;
    border-top: 1px solid #E5E5E5;
  }
  .imgUpload{
    /*width: 95%;*/
    /*height: 44px;*/
    /*background: linear-gradient(90deg, #1DA3F2 0%, #1DC7F2 100%);*/
    /*border-radius: 20px;*/
    /*border: none;*/
    /*font-size: 17px;*/
    /*font-family: PingFang SC;*/
    /*font-weight: bold;*/
    /*color: #FFFFFF;*/
    position: absolute;
    bottom:0px;
    width: 95%;
    height: 44px;
    background: linear-gradient(90deg, #1DA3F2 0%, #1DC7F2 100%);
    border-radius: 22px;
    color: white;
    border: none;
    margin: 10px 2.5% 10px 2.5%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "PingFang SC";
    font-weight: bold;
  }
  .imgUpload img{
    width: 15px;
    height: 15px;
    margin-right: 8px;
  }
  .peopleList{
    height: 230px;
    /*height: 30%;*/
    overflow: auto;
  }
  .peopleDiv {
    width: 95%;
    height: 60px;
    overflow: auto;
    display: flex;
    justify-content: space-between;
    /*padding: 5px;*/
    box-sizing: border-box;
    border-bottom: 1px solid #E5E5E5;
    margin: 10px auto;
    background: #FFFFFF;
    border-radius: 5px;
    padding: 0 10px;
    box-sizing: border-box;
    box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.15);
  }
  .peopleDiv:last-child{
    /*margin-bottom: 30px;*/
  }
  .peopleLeft {
    display: flex;
    align-items: center;
  }
  .peopleContent {
    width: 85%;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
  }
  .peopleContent p{
    display: flex;
    align-items: center;
    padding: 0 10px;
    box-sizing: border-box;
  }
  .peopleContent p span{
    margin-right: 8px;
  }
  .name{
    font-size: 15px;
  }
  .age{
    font-size: 11px;
    color: #999;
  }
  .phone{
    font-size: 13px;
    color: #999;
  }
  .biaoqian{
    width: 30px;
    height: 20px;
    background: #5789ef;
    font-size: 11px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #FFFFFF;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 5px;
  }
  .biaoqianBlue{
    background: #8ED4FC;
  }
  .peopleRight{
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .peopleRight img {
    width: 14px;
    height: 14px;
  }
  .photo{
    width: 40px;
    height: 40px;
  }
  .peopleBottom {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: sticky;
    bottom: 0px;
  }
  .peopleBottom button{
    width: 95%;
    height: 44px;
    background: linear-gradient(90deg, #1DA3F2 0%, #1DC7F2 100%);
    border-radius: 22px;
    color: white;
    border: none;
    margin: 0 auto;
  }
  .imgDiv{
    width: 100%;
    padding: 0 10px;
    box-sizing: border-box;
    display: flex;
    background: #fff;
  }
  .tishi{
    font-size: 13px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #999999;
    padding: 10px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    padding: 0 15px;
    box-sizing: border-box;
    line-height: 1.8;
    background: #fff;
  }
  /*/ 选择框 开始样式/*/
  /deep/ .el-steps--horizontal{
    width: 105%;
  }
  /deep/ .el-step.is-center .el-step__description{
    padding: 0;
  }
  /deep/ .el-step__description{
    margin: 0;
    font-size: 13px;
  }
  /deep/ .el-step__icon{
    width: auto;
    height: auto;
  }
  /deep/ .el-step__icon.is-text{
    border: none;
  }
  /deep/ .is-finish,
  /deep/ .el-step__description.is-process{
    color: #fff;
  }
  /deep/ .el-step__description.is-finish{
    color: white !important;
  }
  /deep/ .el-step__description.is-wait{
    color: rgba(255, 255, 255, 0.7);
  }
  /deep/ .el-step__head.is-finish{
    border-color: #fff;
  }
  /deep/ .el-step__head.is-wait{
    border-color: transparent !important;
  }
  /deep/ .el-step__line{
    border-color: transparent !important;
  }
  /deep/ .el-step.is-horizontal .el-step__line{
    height: 1px;
    /*top:7px;*/
    top: 35%;
  }
  /deep/ .el-step__line{
    background: white;
  }
  /*/ 选择框 结束样式/*/
  /deep/ .van-dialog__header--isolated {
    padding: 24px 10px;
  }
</style>
